---
title: "Ephemeroptera from Brazil"
output:
flexdashboard::flex_dashboard:
source_code: embed
theme: spacelab
social: menu
css: style2.css
editor_options:
chunk_output_type: inline
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(
echo = FALSE,
message = FALSE,
warning = FALSE
)
library(flexdashboard)
library(tidyverse)
library(crosstalk)
library(plotly)
library(viridis)
library(gsheet)
library(leaflet.providers)
library(leaflet)
library(DT)
library(janitor)
```
```{r load data, message=FALSE, warning=FALSE, include=FALSE}
Sys.setlocale("LC_ALL", "pt_BR.UTF-8")
dat1 <- gsheet2tbl("https://docs.google.com/spreadsheets/d/1_FKOEwXyNBgc8MnzMVoQvFsl1Llae_VGNjgj5K0CaH8/edit?usp=sharing")
set.seed(1000)
dat1$lat <- round(jitter(dat1$lat, factor = 1, amount = 0.001), 4)
dat1$lon <- round(jitter(dat1$lon, factor = 1, amount = 0.001), 4)
```
```{r all table, echo=FALSE}
sd <- SharedData$new(dat1)
```
Dashboard
============
Column {.sidebar}
-------------------------------------
### Quick filter
```{r}
filter_slider("year_record", "Restrict to years", sd, ~year_record)
filter_select("family", "Select Family", sd, ~family)
filter_select("genera", "Select Genera", sd, ~genera)
filter_select("species_name", "Select Species name", sd, ~species_name)
filter_checkbox("present_today", "Present today?", sd, ~ present_today,
inline = FALSE)
```
Column {.tabset}
-------------------------------------
### Map strains
```{r}
library(RColorBrewer)
library(htmltools)
pal <- colorFactor("Set3", domain = c("Baetidae",
"Caenidae",
"Coryphoridae",
"Ephemeridae",
"Euthyplociidae",
"Leptohyphidae",
"Leptophlebiidae",
"Melanemerellidae",
"Oligoneuriidae",
"Polymitarcyidae"))
leaflet(data = sd, width = "100%") %>%
setView(-46.8, -18.40, zoom = 4) %>%
addProviderTiles("Esri.WorldImagery", group = "Aerial") %>%
addProviderTiles("OpenTopoMap", group = "Terrain") %>%
addScaleBar("bottomright") %>%
addProviderTiles(providers$CartoDB.Voyager, group = "Default") %>%
addLayersControl(
baseGroups = c("Default", "Aerial", "Terrain"),
options = layersControlOptions(collapsed = T)
) %>%
addCircleMarkers(
radius = 6,
fillOpacity = 1,
weight = 0.5,
label = paste(dat1$family, "- Details"),
fillColor = ~ pal(family),
popup = paste(
"Specimen details
",
"Family:", dat1$"family", "
",
#"Genera:", dat1$"genera", "", "
",
"Species:", dat1$"species_name", "
",
"Author:", dat1$"author", "
",
"Datum:", dat1$"datum", "
",
"Geolocation:", dat1$"geolocation", "
",
"Georeference:", dat1$"georeference", "
",
"Geolocation:", dat1$"geolocation", "
",
#"UC Federal", dat1$"UC_federal", "
",
#"UC non-federal:", dat1$"UC_nofederal", "
",
"Geolocation:", dat1$"geolocation", "
",
#"RPPN:", dat1$"RPPN", "
",
#"Country:", dat1$"country", "
",
#"State:", dat1$"state", "
",
"Municipality:", dat1$"municipality", "
",
"Title:", dat1$"title", "
",
"Literature source:", dat1$"author_record", "
",
"Publication year:", dat1$"year_record", "
"
)
) %>%
addLegend("bottomleft",
pal = pal,
values = ~family,
title = "Family",
opacity = 1
) %>%
addMeasure(
position = "bottomleft",
primaryLengthUnit = "meters",
primaryAreaUnit = "sqmeters",
activeColor = "#3D535D",
completedColor = "#7D4479") %>%
addEasyButton(easyButton(
icon="fa-globe", title="Zoom to Level 4",
onClick=JS("function(btn, map){ map.setZoom(4); }")))
```
### View grid display
```{r}
dat_table <- dat1 %>%
select(year_record, family, genera, species_name, author, present_today, state, municipality)
datatable(dat_table,
extensions = c("Buttons"),
escape = FALSE, rownames = FALSE,
class = "cell-border stripe",
options = list(
extensions = 'Buttons', options = list(
dom = 'Bfrtip',
buttons = c('copy', 'csv', 'excel', 'pdf', 'print')
)
)
)
```
### Chart by host
```{r}
p_family <- dat1 %>%
tabyl(family) %>%
ggplot(aes(reorder(family, n), n))+
geom_col(fill = "#558796")+
theme_minimal()+
coord_flip()+
theme(legend.position = "none",
plot.margin = margin(2, 2, 2, 2, "cm"))+
labs(x = "", y = "Number of records", title = "Family")
ggplotly(p_family)
```
About this dashboard
============
Column {.tabset}
-------------------------------------
### About this database
### How to use it
